package com.whmskj.xjlhbc.mobile.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhbc.domain.Sc18dDailyClassProductionStatist;
import com.whmskj.xjlhbc.domain.StatisticsOnTheDailyProductionOf;
import com.whmskj.xjlhbc.domain.SublistOfDailyAttendanceRecordsF;
import com.whmskj.xjlhbc.dto.QueryDto;
import com.whmskj.xjlhbc.mobile.GetStartDate;
import com.whmskj.xjlhbc.service.IStatisticsOnTheDailyProductionOfService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "产量确认",description = "产量确认")
@RequestMapping("/cl")
public class ClController {

    @Autowired
    private IStatisticsOnTheDailyProductionOfService service;

    //当班产量
    @GetMapping("/list")
    @Operation(description = "列表")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult list(QueryDto param){
        List<SublistOfDailyAttendanceRecordsF> list = service.queryList(param);
        return Page.getDataTable(list);
    }

    //产量统计
    @GetMapping("/tj/list")
    @Operation(description = "产量统计")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, Sc18dDailyClassProductionStatist.class})
    ))
    public AjaxResult tjList(){
        List<Sc18dDailyClassProductionStatist> list = service.tjList();
        return Page.getDataTable(list);
    }

    //日产量
    @GetMapping("/rclList")
    @Operation(description = "日产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, Sc18dDailyClassProductionStatist.class})
    ))
    public AjaxResult rclList(String startDate,String endDate){
        List<Sc18dDailyClassProductionStatist> list = service.rclList(startDate,endDate);
        return Page.getDataTable(list);
    }

    @GetMapping("/list/bzdb")
    @Operation(description = "班组对比")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, Sc18dDailyClassProductionStatist.class})
    ))
    public AjaxResult bzdbList(@RequestParam(required = false) String startDate,
                               @RequestParam(required = false) String endDate){
        DateTime start = StringUtils.hasText(startDate) ?
                DateUtil.beginOfDay(DateUtil.parse(startDate)) :
                DateUtil.parse(GetStartDate.getMonthStartDate());
        DateTime end = StringUtils.hasText(endDate) ?
                DateUtil.endOfDay(DateUtil.parse(endDate)) :
                DateUtil.date();
        Object list = service.bzdbList(start,end);
        return AjaxResult.success(list);
    }

    @GetMapping("/jtcl/list")
    @Operation(description = "机台产量明细")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, StatisticsOnTheDailyProductionOf.class})
    ))
    @Parameter(name = "id",description = "产量确认列表记录id")
    public AjaxResult jtclList(@RequestParam String id){
        List<StatisticsOnTheDailyProductionOf> list = service.jtclList(id);
        return AjaxResult.success(list);
    }

    @PostMapping("/updateJtcl")
    @Operation(description = "机台产量修改,只需要传id和产量两个字段")
    public AjaxResult jtclList(@RequestBody StatisticsOnTheDailyProductionOf body){
        boolean result = service.updateJtcl(body);
        if(result)
            return AjaxResult.success();
        return AjaxResult.error();
    }


    //整经产量-日产量
    @GetMapping("/zj/day")
    @Operation(description = "整经产量-日产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult zjDay(QueryDto param){
        Object result = service.zjDay(param);
        return AjaxResult.success(result);
    }

    //整经产量-日产量
    @GetMapping("/zj/dayDetail")
    @Operation(description = "整经产量-日产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult zjDayDetail(QueryDto param){
        Object result = service.zjDayDetail(param);
        return AjaxResult.success(result);
    }

    //整经产量-月产量
    @GetMapping("/zj/month")
    @Operation(description = "整经产量-月产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult zjMonth(QueryDto param){
        Object result = service.zjMonth(param);
        return AjaxResult.success(result);
    }

    //整经产量-年产量
    @GetMapping("/zj/year")
    @Operation(description = "整经产量-年产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult zjYear(QueryDto param){
        Object result = service.zjYear(param);
        return AjaxResult.success(result);
    }


    //浆纱产量-日产量
    @GetMapping("/js/day")
    @Operation(description = "浆纱产量-日产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult jsDay(QueryDto param){
        Object result = service.jsDay(param);
        return AjaxResult.success(result);
    }

    //浆纱产量-日产量
    @GetMapping("/js/dayDetail")
    @Operation(description = "浆纱产量-日产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult jsDayDetail(QueryDto param){
        Object result = service.jsDayDetail(param);
        return AjaxResult.success(result);
    }

    //浆纱产量-月产量
    @GetMapping("/js/month")
    @Operation(description = "浆纱产量-月产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult jsMonth(QueryDto param){
        Object result = service.jsMonth(param);
        return AjaxResult.success(result);
    }

    //浆纱产量-年产量
    @GetMapping("/js/year")
    @Operation(description = "浆纱产量-年产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class, SublistOfDailyAttendanceRecordsF.class})
    ))
    public AjaxResult jsYear(QueryDto param){
        Object result = service.jsYear(param);
        return AjaxResult.success(result);
    }

    //整理产量
    @GetMapping("/zlCl")
    @Operation(description = "浆纱产量-年产量")
    @ApiResponse(content = @Content(
            schema = @Schema(anyOf = {AjaxResult.class})
    ))
    public AjaxResult zlCl(String month){
        Object result = service.zlCl(month);
        return AjaxResult.success(result);
    }
}
